package club.mzywucai.blog.file_system.pojo.domain;

import lombok.Data;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author mzywucai
 * @Description 修改背景
 * @date 2019/4/2
 */
@Component
public class ChangeImageAndSentence {

    private String[] sentenceArr = {
            "与其抱怨身处黑暗，不如提灯前行。",
            "我现在顾不得伤痛，因为我知道大世界要来了。",
            "孤独和情绪管理，是你迟早需要面对的必修课。",
            "如何让自己的有趣更长久的保值而又不至于让人厌烦？倾听和观察的学习永远是第一要义。",
            "这个世界的顶梁柱由一群疯子组成，而这些疯子和疯子之间，大都互相讨厌。",
            "生活是一场长跑，莫一时耗光所有的精力，眼下的得失计较为时尚早，不妨把时间轴拉长一点。",
            "能看见八方来客，才知己见索然。",
            "世人皆苦，向死而生。一路行来，诸多不易，望多珍重。",
            "一身的代码味，就和烟味一个样子。",
            "从聆听者，到转述者，到思考者，到开创者。",
            "年少时见过花，是红色的；年轻时见过海，是蓝色的；现在我的对面有个陌生人，他没有颜色。",
            "不要怀疑你受过的苦难，这都会让你更好。",
            "Everything I do, every minute I spend, is my choice.",
            "But mine is all as hungry as the sea, and can digest as much."
    };
    String[] backgroundArr = new String[10];
    String[] indexImageArr = new String[12];

    private String backgroundBasic = "/images/default/background/";
    private String indexImageBasic = "/images/index/";

    private String background = backgroundBasic + "background01.jpg";
    private String indexImage = indexImageBasic + "index01.jpg";
    private String sentence = sentenceArr[0];



    private int backgroundNo = 0;
    private int indexImageNo = 0;
    private int sentenceNo = 0;

    private boolean flag = true;


    // @Scheduled(cron = "0 0 0 * * ?")
    @Scheduled(fixedRate = 15000)
    // @Scheduled(cron = "0 0/1 * * * ?")
    public void changeImageAndSentence() {
        backgroundNo++;
        indexImageNo++;
        sentenceNo++;


        if (flag) {
            getBackgroundArr(backgroundArr);
            getIndexImageArr(indexImageArr);
        }

        if (backgroundNo == backgroundArr.length) {
            backgroundNo = 0;
        }
        if (indexImageNo == indexImageArr.length) {
            indexImageNo = 0;
        }
        if (sentenceNo == sentenceArr.length) {
            sentenceNo = 0;
        }

        background = backgroundArr[backgroundNo];
        indexImage = indexImageArr[indexImageNo];
        sentence = sentenceArr[sentenceNo];

        flag = false;

        System.out.println("backgroundNo = " + backgroundNo + ", indexImageNo = " + indexImageNo + ", sentenceNo = " + sentenceNo);
    }

    private void getBackgroundArr(String[] backgroundArr) {
        for (int i=1; i<=backgroundArr.length; i++) {
            backgroundArr[i-1] = backgroundBasic + "background0" + i + ".jpg";
        }
    }

    private void getIndexImageArr(String[] indexImageArr) {
        for (int i=1; i<=indexImageArr.length; i++) {
            indexImageArr[i-1] = indexImageBasic + "index0" + i + ".jpg";
        }
    }

    /**
     * @Description 拿到背景
     * @author mzywucai
     * @time 2019-04-03
     * @see
     * @return   java.lang.String
     * @params  []
     */
    public String getBackground() {
        return this.background;
    }

    /**
     * @Description 拿到首页图像
     * @author mzywucai
     * @time 2019-04-03
     * @see
     * @return   java.lang.String
     * @params  []
     */
    public String getIndexImage() {
        return this.indexImage;
    }

    /**
     * @Description 拿到句子
     * @author mzywucai
     * @time 2019-04-03
     * @see
     * @return   java.lang.String
     * @params  []
     */
    public String getSentence() {
        return this.sentence;
    }


}